#ifndef ASNODEMEM_H
#define ASNODEMEM_H
#include "global.h"
namespace tinyscript{
namespace internal{

class ASNodeMemoryPool {
public:
    void* New();
    void Delete( void* ptr );
    ASNodeMemoryPool(size_t sz , size_t objsize);
    ~ASNodeMemoryPool();

    void set_grow_size( size_t sz ) {
        grow_size_ = sz;
    }
    size_t grow_size() const {
        return grow_size_;
    }
private:

    void Grow();
    void Destroy();

private:
	struct MempoolHeader {
		struct MempoolHeader* next;
	};
	MempoolHeader* pool_;
	struct FreelistHeader {
		struct FreelistHeader* next;
	};

private:
    MempoolHeader* MHeader( void* b ) {
        return (MempoolHeader*)(b);
    }

    FreelistHeader* FHeader( void* b ) {
        return (FreelistHeader*)(b);
    }

    void* BufferMove( void* b , size_t sz ) {
        return (void*)(( char* )(b) + sz);
    }

private:
    FreelistHeader* header_;
    size_t grow_size_;
    size_t object_size_;
};


}
}

#endif // ASNODEMEM_H
